using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace IEeee
{
    public partial class AddNewServer : Form
    {

        private String m_ServerURL;


        public AddNewServer()
        {
            InitializeComponent();
        }

        public String ServerURL
        {
            get { return m_ServerURL; }
        }

        private void AddNewServer_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                if (IsValidURL)
                {
                    m_ServerURL = txtUrl.Text;
                }
                else
                {
                    MessageBox.Show(this, "This is not a valid URL", "IEeee!",
                                     MessageBoxButtons.OK, MessageBoxIcon.Error);
                    e.Cancel = true;
                }
            }
        }

        private bool IsValidURL
        {
            get { return Uri.IsWellFormedUriString(txtUrl.Text, UriKind.Absolute); }
        }

        private void AddNewServer_HelpButtonClicked(object sender, CancelEventArgs e)
        {
            e.Cancel = true;
            System.Diagnostics.Process.Start("http://www.codeplex.com/UKVSTS/Wiki/View.aspx?title=Add%20New%20Server");
        }

        private void txtUrl_TextChanged(object sender, EventArgs e)
        {
            Color foreCol = SystemColors.WindowText;
            Color backCol = SystemColors.Window;
            if (IsValidURL) {
                foreCol = SystemColors.InfoText;
                backCol = SystemColors.Info;
            }

            if (txtUrl.ForeColor != foreCol) {
                txtUrl.ForeColor = foreCol;
                txtUrl.BackColor = backCol;
            }
        }
    }
}